package com.ygj.duty.action;

import com.base.common.action.AbstractBaseAction;
import com.base.common.bean.ActionResult;
import com.cjy.common.bean.OpAttributes;
import com.ygj.dept.service.DeptService;
import com.ygj.duty.service.DutyService;
import lombok.Getter;
import lombok.Setter;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import javax.annotation.Resource;

import static com.base.common.GlobaConstants.*;

/**
 * 部门action
 * 
 * @author Kevin Colin
 * @datetime 2015年9月15日下午5:01:29
 *
 */
@Action("dutyAction")
@Results({ @Result(name = ASYNCHRONOUS, type = JSON, params = { ROOT,
		ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_JSON }) })
public class DutyAction extends AbstractBaseAction {

	private static final long serialVersionUID = 1L;
	@Resource
	private DutyService dutyService;

	@Getter @Setter
	private int compoundsId;

	@Getter @Setter
	private String queryTime;

	@Getter @Setter
	private int employeeId;

    @Getter @Setter
    private String remarks;

    @Getter @Setter
    private int user_id1;

    @Getter @Setter
    private int user_id2;

    @Getter @Setter
    private int dutyId;


	public String queryDutyInfo(){
		try {
			actionResult = new ActionResult(new OpAttributes<>().add("code", 1).add("result", dutyService.queryDutyInfo(compoundsId, queryTime)));
		} catch (Exception  e) {
			e.printStackTrace();
			actionResult = new ActionResult(new OpAttributes<>().add("code", 0));
		}
		return returnType();
	}

	public String queryDutyPlan() {
		try {
			actionResult = ActionResult.getActionResult(new OpAttributes<>().add("code", 1).add("result", dutyService.queryDutyPlan(employeeId)));
		} catch (Exception e) {
			e.printStackTrace();
			actionResult = ActionResult.getActionResult(new OpAttributes<>().add("code", 0));
		}
		return returnType();
	}

    public String upadteDutyPlan() {
        try {
            actionResult = ActionResult.getActionResult(new OpAttributes<>().add("code", dutyService.updateDutyPlan(remarks, user_id1, user_id2, dutyId, compoundsId)));
        } catch (Exception e) {
            e.printStackTrace();
            actionResult = ActionResult.getActionResult(new OpAttributes<>().add("code", 0));
        }
        return returnType();
    }
}
